package top.caoayu.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import top.caoayu.base.entity.Article;
import top.caoayu.base.entity.Comment;
import top.caoayu.base.entity.dto.ArticleCreateDTO;
import top.caoayu.base.entity.dto.ArticleDTO;
import top.caoayu.base.entity.dto.ArticleQueryDTO;
import top.caoayu.base.entity.vo.AritcleVo;
import top.caoayu.base.mapper.ArticleMapper;
import top.caoayu.base.service.IArticleService;
import top.caoayu.base.service.ICommentService;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements IArticleService {


    @Override
    public Page<AritcleVo> page(ArticleQueryDTO articleDTO) {
        return null;
    }

    @Override
    public int insert(ArticleCreateDTO articleDTO) {
        Article article = new Article();
        BeanUtils.copyProperties(articleDTO, article);
        return this.save(article)?1:0;
    }

    @Override
    public ArticleDTO getDetail(ArticleQueryDTO articleQueryDTO) {
        Article article = this.getById(articleQueryDTO.getId());
        QueryWrapper<Comment> commentQueryWrapper = new QueryWrapper<>();
        commentQueryWrapper.eq("article_id", articleQueryDTO.getId()).eq("is_delete", 0);
//        Page<Comment> commentPage = commentService.getBaseMapper().selectPage(articleQueryDTO.getPage(), commentQueryWrapper);
        ArticleDTO articleDTO = new ArticleDTO();
        BeanUtils.copyProperties(article, articleDTO);
//        articleDTO.setComments(commentPage.getRecords());
        return articleDTO;
    }

    public int reallyDelete(Long id) {
        return this.removeById(id)?1:0;
    }

    public void reallyDeleteAll() {
    }
}
